package com.twu.solo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Arrays.asList;

/**
 * Created with IntelliJ IDEA.
 * User: thoughtworker
 * Date: 10/10/13
 * Time: 4:50 PM
 * To change this template use File | Settings | File Templates.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        new FootballLeagueManagerApp(setupMenu(), new BufferedReader(new InputStreamReader(System.in)), commandSetup()).runApplication();
    }

    private static Menu setupMenu() {
        MenuOption menuOption1 = new MenuOption("View All Players in League", 1);
        MenuOption menuOption2 = new MenuOption("Find Player in League By Name", 2);
        return new Menu(System.out, asList(menuOption1, menuOption2));
    }
    private static Team teamSetup(String teamName, String player1name, String player2name, Coach coach) {
        List<Player> players =  Arrays.asList(new Player(player1name, teamName, 1, 30, System.out), new Player(player2name, teamName, 2, 30, System.out));
        List<Coach> coaches = Arrays.asList(coach) ;
        Team team = new Team(teamName, System.out, players, coaches);
        return team;
    }

    private static League leagueSetup() {
        Team team1 = teamSetup("Team Name1", "Joe", "Jack", new Coach("bob lahblah", "head coach1"));
        Team team2 = teamSetup("Team Name2", "Jerry", "Jon", new Coach("abraham cadabra", "head coach2"));
        Team team3 = teamSetup("Team Name3", "Joseph", "Junior", new Coach("Tiberius Rex", "head coach3"));
        League league = new League(System.out, Arrays.asList(team1, team2, team3));
        return league;
    }

    private static Map<String, Command> commandSetup() {
        Map<String,Command> commandMap = new HashMap<String, Command>();
        commandMap.put("1", new DisplayLeaguePlayerListCommand(leagueSetup()));
        commandMap.put("2", new AllowUserToSearchForPlayerByNameCommand(System.out, new BufferedReader(new InputStreamReader(System.in)),leagueSetup()));
        commandMap.put("invalid", new DisplayInvalidOptionCommand(System.out));
        return commandMap;
    }
}
